<style>
.main-tags{
  -webkit-box-shadow: 0 2px 3px rgba(0,0,0,.20);
  box-shadow: 0 2px 3px rgba(0,0,0,.20);
}
.main-tags ul{
  position: relative;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: -moz-flex;
  display: -ms-flex;
  display: flex;
  display: inline-flex;
  white-space:nowrap;
  margin: 0 auto;
  padding: 0;
  max-width: 1200px;
  list-style: none;
  overflow: hidden;
  justify-content: center;
}
.main-tags ul li{
  float: left;
  padding-top: 2px;
  padding-bottom: 3px;
  position: relative;
  z-index: 1;
  display: inline-block;
  margin: 0;
  text-align: center;
  -webkit-flex: 1;
  -moz-flex: 1;
  -ms-flex: 1;
  /*border-radius: 18px;*/
}
.main-tags a{
  color: #555;
  line-height: 1;
  padding:0 16px;
  position: relative;
  display: block;
  /*overflow: hidden;*/
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 2.5;

}
.tab-current{
  background: #fff;
  border-left: 1px solid #eee;
  border-right: 1px solid #eee;
}
.main-tags li.tab-current a {
  color: #2298d1;
  -webkit-transform: translate3d(0,3px,0);
  transform: translate3d(0,2px,0);
}
.main-tags .tab-current::before{
  opacity: 1;
  -webkit-transform: scale3d(1,1,1);
  transform: scale3d(1,1,1);
}
.main-tags li::before{
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 3px;
  opacity: 0;
  background: #2298d1;
  content: '';
  -webkit-transition: -webkit-transform 0.3s ease-in;
  transition: transform 0.3s ease-in;
  -webkit-transform: scale3d(0,1,1);
  transform: scale3d(0,1,1);
}
.tab-current .ivu-icon-close-circled{
  transform: scale(1.2,1.2);
  -ms-transform:scale(1.2,1.2); /* IE 9 */
  -moz-transform:scale(1.2,1.2); /* Firefox */
  -webkit-transform:scale(1.2,1.2); /* Safari and Chrome */
}
.tab-current .ivu-icon-close-circled:hover{
  color: #ff9900;
}
.tags-left{
  float: right;
  background: #fff;
}
.tags-left i{
  line-height: 40px;
}
</style>
<template>
  <div class="main-tags">
    <div class="tags-left">
      <!-- <ButtonGroup shape="circle">
        <Button type="ghost" icon="ios-skipbackward"></Button>
        <Button type="ghost" icon="ios-skipforward"></Button>
      </ButtonGroup> -->
    </div>
      <ul>
        <li @click="setTagsClass($index)" :class="tag.name==currentPage?'tab-current':''" v-for="(tag,$index) in taglist"><a><Icon :type="tag.icon"/> {{tag.name}} &nbsp;&nbsp;<span @click.stop="deleteTag($index)"><Icon v-if="$index>0" type="close-circled"></Icon></span></a></li>
      </ul>
  </div>
</template>
<script>
    export default {
    	data:function(){
    		return {
          taglist:[],
          currentPage:''
    		}
    	},
      computed: {
        tagList() {
          return this.$store.state.tagList;
        },
        currentPageName (){
          return this.$store.state.currentPageName;
        }
      },
      watch: {
        tagList(val) {
          this.init(val);
        },
        currentPageName(val){
          this.currentPage = val;
        }
      },
      created:function(){
        this.init(this.$store.state.tagList);
        this.setTagsClass(0);
      },
			methods: {
        init:function(arr){
          var arrP = [];
          for(var i =0;i<arr.length;i++ ){
            arrP.push({name:arr[i].name,class:'',icon:arr[i].icon});
          }
          this.taglist = arrP;
        },
        setTagsClass:function(index) {
          for(var i = 0;i<this.taglist.length;i++){
            if(i==index){
              this.$set(this.taglist[index],'class','tab-current');
            }else {
              this.$set(this.taglist[i],'class','');
            }
          }
          this.$store.commit('setCurrentPage',this.taglist[index].name);
        },
        deleteTag:function(index){
          this.$store.commit('deleteSideBar',index);
          this.taglist.splice(index,1);
          this.$store.commit('setCurrentPage',this.taglist[this.taglist.length-1].name);
        },
        //获取伪类的对象，这里没有用到
        ruleSelector:function(selector) {
          function uni(selector) {
            return selector;
          }
          return Array.prototype.filter.call(Array.prototype.concat.apply([], Array.prototype.map.call(document.styleSheets, function(x) {
            return Array.prototype.slice.call(x.cssRules);
          })), function(x) {
            return uni(x.selectorText) === uni(selector);
          });
        }
			}
    };
</script>
